package com.item.yxlottery.yxlottery.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.item.yxlottery.yxlottery.R;

import java.util.List;
import java.util.Map;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2016/12/23 10:51
 * @文件描述    已开奖的可折叠list里面的奖金分配表格adapter
 *------------------------------
 */

public class TableAdapter extends BaseAdapter {

    private List<Map<String, Object>> dataList;
    private LayoutInflater mInflater;

    public TableAdapter(Context context, List<Map<String, Object>> dataList) {
        mInflater = LayoutInflater.from(context);
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_expandable_row, parent, false);
        }
        TextView tvTitle = (TextView) convertView.findViewById(R.id.tv_expandable_row);
        Map<String, Object> item = dataList.get(position);
        tvTitle.setText((String) item.get("title"));
        if ((position + 1) < 4) {//第一行
            tvTitle.setTextColor(0xff999999);
            if ((position + 1) == 3) {//第一行的第三列
                tvTitle.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
            }
        } else if ((position + 1) > 3 && (position + 1) % 3 == 0) {
            tvTitle.setTextColor(0xffff0000);
            tvTitle.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
        } else {
            tvTitle.setTextColor(0xff333333);
        }
        return convertView;
    }
}
